package com.ruoyi.project.system.memberdepartment.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.memberdepartment.domain.MemberDepartment;
import com.ruoyi.project.system.memberdepartment.service.IMemberDepartmentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 申请捆绑企业部门Controller
 *
 * @author LCL
 * @date 2022-01-04
 */
@Controller
@RequestMapping("/system/memberdepartment")
public class MemberDepartmentController extends BaseController
{
    private String prefix = "system/memberdepartment";

    @Autowired
    private IMemberDepartmentService memberDepartmentService;

    @RequiresPermissions("system:memberdepartment:view")
    @GetMapping()
    public String memberdepartment()
    {
        return prefix + "/memberdepartment";
    }

    /**
     * 查询申请捆绑企业部门列表
     */
    @RequiresPermissions("system:memberdepartment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberDepartment memberDepartment)
    {
        startPage();
        List<MemberDepartment> list = memberDepartmentService.selectMemberDepartmentList(memberDepartment);
        return getDataTable(list);
    }

    /**
     * 导出申请捆绑企业部门列表
     */
    @RequiresPermissions("system:memberdepartment:export")
    @Log(title = "申请捆绑企业部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberDepartment memberDepartment)
    {
        List<MemberDepartment> list = memberDepartmentService.selectMemberDepartmentList(memberDepartment);
        ExcelUtil<MemberDepartment> util = new ExcelUtil<MemberDepartment>(MemberDepartment.class);
        return util.exportExcel(list, "memberdepartment");
    }

    /**
     * 新增申请捆绑企业部门
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存申请捆绑企业部门
     */
    @RequiresPermissions("system:memberdepartment:add")
    @Log(title = "申请捆绑企业部门", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberDepartment memberDepartment)
    {
        return toAjax(memberDepartmentService.insertMemberDepartment(memberDepartment));
    }

    /**
     * 修改申请捆绑企业部门
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MemberDepartment memberDepartment = memberDepartmentService.selectMemberDepartmentById(id);
        mmap.put("memberDepartment", memberDepartment);
        return prefix + "/edit";
    }

    /**
     * 修改保存申请捆绑企业部门
     */
    @RequiresPermissions("system:memberdepartment:edit")
    @Log(title = "申请捆绑企业部门", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberDepartment memberDepartment)
    {
        return toAjax(memberDepartmentService.updateMemberDepartment(memberDepartment));
    }

    /**
     * 删除申请捆绑企业部门
     */
    @RequiresPermissions("system:memberdepartment:remove")
    @Log(title = "申请捆绑企业部门", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberDepartmentService.deleteMemberDepartmentByIds(ids));
    }
}
